Omplus.views.SearchPanel = Omplus.base.extend(Omplus.views.Panel, {
    omplusType:"SearchPanel",
    init : function(){
        this.width = this.pixelsWidth + "px";
        this.layout.width = (this.pixelsWidth - 30) + "px";
        this.fieldProto.model = this.models.search;
        this.fieldProto.controller = this.controller;
        if (this.views.search && this.views.search.length) {
            this.searchProto = jQuery.extend(true, {}, this.tabProto);
            var horizontal = {
                omplusType:"Panel",
                components:[],
                width:Math.ceil((this.pixelsWidth - 50) / 3) + "px"
            };
            this.searchProto.omplusName = this.omplusName + "_searchTab";
            this.searchProto.model = "Assets.list.label_search_button.localValue";
            this.searchProto.controller = "languageController";
            this.searchProto.components = new Array();
            for (var i = 0; i < 3; i++) {
                horizontal.omplusName = this.omplusName + "_panelLayout_" + i;
                this.searchProto.components.push(jQuery.extend(true, {}, horizontal));
                this.searchProto.components[i].omplusName = this.omplusName + "_search_" + i;
            }
            var columns = Math.ceil(this.views.search.length / 3);
            for (var i in this.views.search) {
                var helper = jQuery.extend(true, {}, this.fieldProto);
                helper = jQuery.extend(true, helper, this.views.search[i]);
                helper.omplusName = this.omplusName + "_field_" + i;
                if (this.views.search[i].inputType)
                    helper.inputType = this.views.search[i].inputType;
                if (!helper.controller)
                    helper.controller = this.controller;
                helper.labelModel = this.views.search[i].labelModel;
                var panel = this;
                if (helper.perPage) {
                    helper.omplusName = this.omplusName + "_perPage";
                    var helperNew = helper;
                    helper.select = function () {
                        Omplus.globals.getObject(panel.omplusName + "_tableResult").changePerPage(Omplus.globals.getObject("PerPages." + helperNew.current +".number").getValue());
                    }
                }
                if (helper.searchButton) {
                    helper.omplusName = this.omplusName + "_searchButton";
                    helper.click = function () {
                        panel.actions[0].run();
                    }
                }
                this.searchProto.components[Math.floor(i / columns)].components.push(helper);
            }
            if (this.views.searchResult && this.views.searchResult.length) {
                this.tableProto.omplusName = this.omplusName + "_table";
                this.tableProto.components[0].omplusName = this.omplusName + "_tableColumns";
                var tableRowProto = {
                    omplusType:this.omplusName + "_rowProto",
                    components:[]
                };
                for (var i in this.views.searchResult) {
                    if (!this.views.searchResult[i].getDetails) {
                        var label = jQuery.extend(true, {}, {
                            omplusType:"Label",
                            omplusName:this.omplusName + "_tableColumns_" + this.views.searchResult[i].model,
                            model:this.views.searchResult[i].labelModel,
                            controller:"languageController",
                            width:this.views.searchResult[i].width,
                            render:function () {
                                this.getContent().css({"margin-top":"20px"})
                            }
                        });
                        this.tableProto.components[0].components.push(label);
                        var column = jQuery.extend(true, {}, {
                            omplusType:this.views.searchResult[i].omplusType,
                            omplusName:this.omplusName + "_tableRow_" + this.views.searchResult[i].model,
                            model:this.views.searchResult[i].model,
                            width:this.views.searchResult[i].width
                        });
                        tableRowProto.components.push(column);
                        this.tableProto.components[1].rowCellWidths.push(this.views.searchResult[i].width);
                    }else{
                        var panel = this;
                        var column = jQuery.extend(true, {}, {
                            omplusType:this.views.searchResult[i].omplusType,
                            omplusName:this.omplusName + "_tableRow_" + i,
                            model:this.views.searchResult[i].model,
                            controller: this.views.searchResult[i].controller,
                            width:this.views.searchResult[i].width,
                            click:function () {
                                var array = $(this).closest(".tableRow").attr("id").split("_");
                                var row = array[array.length - 1];
                                var action = panel.actions[1];
                                _omplusConstants.opened_button = $(this);
                                _omplusConstants.opened_button.hide();
                                action.requestModel = helper.models.searchResult + "." + helper.models.searchResultList + ".member." + row;
                                action.run();
                            }
                        });
                        tableRowProto.components.push(column);
                        this.tableProto.components[1].rowCellWidths.push(this.views.searchResult[i].width);
                    }
                }
                Omplus.views[tableRowProto.omplusType] = Omplus.base.extend(Omplus.views.TableRow, tableRowProto);
                this.tableProto.components[1].omplusName = this.omplusName + "_tableResult";
                this.tableProto.components[1].controller = this.controller;
                this.tableProto.components[1].definition = {
                    ownerOfAction : this.omplusName,
                    nameOfAction : "searchResult",
                    list : this.models.searchResultList,
                    modelSearch : this.models.search
                };
                this.tableProto.components[1].omplusProto = this.omplusName + "_rowProto";
                this.tableProto.components[1].model = this.models.searchResult;
                this.searchProto.components.push(this.tableProto);
            }
            Omplus.base.create(Omplus.views.Panel, {
                omplusName:this.omplusName + "_tableOverlay",
                renderTo:this.omplusName + "_searchTab",
                width:Math.ceil(this.pixelsWidth - 50) + "px",
                showEffect:{
                    name:"fade",
                    time:1
                },
                hideEffect:{
                    name:"fade",
                    time:1
                }
            });
            var array = new Array();
            array.push(this.searchProto);
            for (var i in this.components) {
                array.push(this.components[i]);
            }
            this.components = array;
        }
        if (this.models.search){
            for (var i in this.actionsProto) {
                switch (this.actionsProto[i].omplusName) {
                    case "searchResult":
                        this.actionsProto[i].requestModel = this.models.search;
                        this.actionsProto[i].responseModel = this.models.searchResult;
                        var helper = this;
                        this.actionsProto[i].start = function () {
                            Omplus.globals.getObject(helper.omplusName + "_tableOverlay").show();
                        };
                        this.actionsProto[i].callback = function () {
                            helper.callback();
                            Omplus.globals.getObject(helper.omplusName + "_tableOverlay").hide();
                        };
                        break;
                }
                this.actionsProto[i].omplusName = this.omplusName + "." + this.actionsProto[i].omplusName;
                this.actions.push(Omplus.base.create(Omplus.actions[this.actionsProto[i].omplusType], this.actionsProto[i]));
            }
        }
    },
    layout:{
        omplusType:"VerticalLayout"
    },
    height:"auto",
    pixelsWidth:950,
    controller:null,
    models:{
        search:null,
        searchResult:null,
        searchResultList:null
    },
    views:{
        search:[],
        searchResult:[]
    },
    fieldProto:{
        omplusType:"LabelInputPair",
        labelController:"languageController",
        width:"100%",
        height:"50px"
    },
    actions : [],
    actionsProto:[
        {
            omplusType:"Get",
            omplusName:"searchResult",
            proxy:{
                omplusType:"AjaxProxy"
            }
        }
    ],
    tabProto:{
        omplusType:"Panel",
        layout:{
            omplusType:"HorizontalLayout"
        },
        controller:"languageController",
        model:"Assets.list.players_label.localValue"
    },
    tableProto:{
        omplusType:"Panel",
        components:[
            {
                omplusName:"tableColumnNameLabels",
                omplusType:"Panel",
                components:[],
                cssClasses:[
                    "table-header"
                ]
            },
            {
                omplusType:"DinamicTable",
                orientation:"vertical",
                rowsPerPage:5,
                rowHeight:"35px",
                rowCellWidths:[]
            }
        ]
    },
    getAction:function (actionName) {
        return Omplus.globals.getObject(this.omplusName + "." + actionName);
    },
    callback : function(){}
});